<?php
namespace TwinPeaks\Core;

class CCommonException extends CBaseException
{
	const FC_NO_RULE_MATCHED = 1;
	const NO_FC_MATCHED = 2;
	const FILTER_NO_PARAM_VALUE = 3;
	const FILTER_NO_PARAM_DEF = 4;
	const HTTP_REQUEST_METHOD_NOT_ALLOWED = 5;
	
	function __construct($message, $code) 
	{
		parent::__construct($message, $code);
		$this->setClass(COMMON_EXCEPTION_CLASS);
	}
	
	/**
	 * @return CCommonException
	 */
	static function noRule($FC, $requestURI)
	{
		return new static(
			sprintf('No rule of the front controller `%s` has matched the request URI %s',
				get_class($FC), $requestURI->toString()), self::FC_NO_RULE_MATCHED
		);
	}
	
	/**
	 * @return CCommonException
	 */
	static function noFrontController($requestURI)
	{
		return new static(
			sprintf('No front controller has matched the request URI %s',
				$requestURI->toString()), self::NO_FC_MATCHED
		);
	}
	
	/**
	 * @return CCommonException
	 */
	static function filterNoParamValue($paramName)
	{
		return new static(sprintf('No value for the parameter `%s`', $paramName),
			self::FILTER_NO_PARAM_VALUE);
	}
	
	/**
	 * @return CCommonException
	 */
	static function filterNoParamDef($paramName)
	{
		return new static(sprintf('No definition of the parameter `%s`', $paramName),
			self::FILTER_NO_PARAM_DEF);
	}
	
	/**
	 * @return CCommonException
	 */
	static function httpRequestMethodNotAllowed()
	{
		return new static(sprintf('%s method is not allowed', $_SERVER['REQUEST_METHOD']),
			self::HTTP_REQUEST_METHOD_NOT_ALLOWED);
	}
}
